package com.qfjy.mapper;

import com.qfjy.entity.MeetingGrab;
import com.qfjy.entity.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.LinkedList;
import java.util.List;

public interface MeetingGrabMapper {
    int deleteByPrimaryKey(String id);

    int insert(MeetingGrab record);

    int insertSelective(MeetingGrab record);

    MeetingGrab selectByPrimaryKey(String id);

    int updateByPrimaryKeySelective(MeetingGrab record);

    int updateByPrimaryKey(MeetingGrab record);

    /**
     * 查询我的抢单列表
     * @param uid
     * @return
     */
  List<MeetingGrab> selectMeetingGrabListByUid(String uid);


    /**
     * 查询抢单个人信息
     */
    List<User> selectUserInfoByUid(String pid);
    /**
     * 就选你功能
     */
    @Update("update meetinggrab set grabStatus=2,grabDate=now() where pid=#{pid}")
    int updataMeetingGrabChooseFail(String pid);


    @Update("update meetinggrab set grabStatus=1,grabDate=now() where uid=#{uid} and pid=#{pid}")
    int updataMeetingGrabChooseSuccess(String uid,String pid);

      @Select("select wei.nickname,wei.headimgurl, \n" +
              "SUM(CASE WHEN  grab.grabStatus=1 THEN 1 ELSE 0 END) as pubSuccCount from meetinggrab  p \n" +
              "LEFT JOIN user u ON p.uid=u.id\n"+
              "LEFT JOIN weiuser wei ON u.wid=wei.id\n" +
              "LEFT JOIN meetinggrab grab ON u.id=grab.uid  AND grab.grabStatus=1\n" +
              "GROUP BY p.uid ORDER BY pubSuccCount DESC;")
    LinkedList<MeetingGrab> selectQOrderBy();

}